package org.csu.mypetstore.web.servlets;

import org.csu.mypetstore.domain.Order;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ShippingOrderServlet extends HttpServlet {
    private static final String CONFIRM_ORDER = "/WEB-INF/jsp/order/ConfirmOrder.jsp";

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Order order = (Order)req.getSession().getAttribute("order");

        if(req.getParameter("shippingFormFilled") != null && req.getParameter("shippingFormFilled").equals("true")){
            String shipAddress1 = req.getParameter("shipAddress1");
            String shipAddress2 = req.getParameter("shipAddress2");
            String shipCity = req.getParameter("shipCity");
            String shipState = req.getParameter("shipState");
            String shipZip = req.getParameter("shipZip");
            String shipCountry = req.getParameter("shipCountry");
            String shipToFirstName = req.getParameter("shipToFirstName");
            String shipToLastName = req.getParameter("shipToLastName");

            order.setShipAddress1(shipAddress1);
            order.setShipAddress2(shipAddress2);
            order.setShipCity(shipCity);
            order.setShipState(shipState);
            order.setShipZip(shipZip);
            order.setShipCountry(shipCountry);
            order.setShipToFirstName(shipToFirstName);
            order.setShipToLastName(shipToLastName);
        }

        req.getRequestDispatcher(CONFIRM_ORDER).forward(req, resp);//跳转到确认页面
    }
}
